package com.qf.item.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.qf.item.mapper.ItemMapper;
import com.qf.item.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Service
public class ItemServiceImpl implements ItemService {

    @Resource
    private ItemMapper itemMapper;

    @Autowired
    private RestTemplate restTemplate;

    @Override
    @Transactional
    @LcnTransaction
    public void updateStock() {
        // 调用订单模块,创建订单
        String result = restTemplate.getForObject("http://localhost:8080/order/add", String.class);
        //  订单创建成功

//        int i = 1 / 0;   // 抛出异常

        // 减库存
        itemMapper.updateStock();
        // 减库存失败....
    }
}
